package com.zg.system.auth;

import cn.hutool.core.util.RandomUtil;
import com.zg.common.core.R;
import com.zg.common.core.dao.system.SysThird;
import com.zg.common.core.dao.system.SysThirdDao;
import com.zg.common.core.util.IdUtil;
import com.zg.common.log.LogRequest;
import com.zg.common.log.OpTypeEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Zxb
 */
@RestController
@RequiredArgsConstructor
public class ThirdController {
    private final SysThirdDao thirdDao;

    @PostMapping("/un/third/generate")
    @LogRequest(opModule = "第三方系统管理", opName = "创建第三方系统", opType = OpTypeEnum.LOGIN)
    public R createToken() {
        SysThird obj = new SysThird();
        obj.setName("第三方系统");
        obj.setCode(RandomUtil.randomString(6));
        obj.setAppKey(IdUtil.nextIdStr());
        obj.setAppSecret(RandomUtil.randomString(16));
        thirdDao.save(obj);
        return R.success(obj);
    }
}
